Drupal custom module code working differently for logged in users and anonymous users
This sounds like a caching issue. Check the cache api and make sure to set the $form['#cache'] appropriately. 

When the anonymous user submits the form, it's submitted fine, but when the form loads the second time Drupal doesn't know that it should not be serving the original cached form.

You can quickly confirm that it is a caching issue by set the form to not be cached like:

$form['#cache'] = [
  'max-age' =&gt; 0,
];