Add list item to list, items changed order

Hello guys,
I am creating an app to make quizzes and it is already in an advanced stage, but I've noticed this problem a week ago and it's driving me insane because I can't figure out what is wrong. Maybe it's a bug, I think.

So I have a page to edit the quizzes, which are initially read and then saved to a .txt file. Simplifying in the designer I have 5 textboxes (1 for entering the question and 4 for the options), 4 checkboxes (to select the only correct answer), and buttons to go to the next and previous question and to create more questions. Every time I click to go to a different question it updates the list where I have the questions saved and loads the textboxes' text with the next question, so I can change them. In the end, I hit Save and the list is saved again in the .txt file. The questions are saved in the .txt file one question per line, separated with semi-colons (Question;nr_for_the_correct_option;Option_1;Option_2;Option_3;Option_4). While editing they are saved in a list of lists in the same order as the .txt file.

My issue: everything works fine (loading and presenting the questions, changing questions, selecting the correct option, etc), except for saving the file. Most of the times works ok, but once in a while, it changes the order of the options only in some questions (for example: "nr_for_the_correct_option;Question;Option_1;Option_2;Option_3;Option_4", this is the order that happens the most, and happens mostly on the first question). I always try to produce the same error, repeating my steps, but when I do the exact same thing again, the problem doesn't happen. As I said it only happens sometimes even with the same steps and text, so I can't figure out what's wrong... maybe some kind of delay??

Here are my relevant blocks:

"altera_pergunta" is the function to update the list of questions every time I go to the next or previous question, "recebe_correta" if for getting the correct option from the checkboxes, "gravar2" is the function that happens in the end to update the file.

I appreciate it if you can help me.
Thanks and sorry for the extent of the post.

I see you issuing multiple Append to File requests in quick succession.
I also see no use of the when File1.AfterFileSaved event block.

I infer from the existence of that event block that you might have to control the timing of your Appends using that event block.

Alternatively, if you package your questions and answers into a list of dictionaries, AI2 can marshall that into JSON text when you write it out as text to a file.
The Web component has a block to decode JSON back into dictionaries and lists.

The conversions automatically wrap text with quotes to guard against characters that would break the packing and unpacking.

Thank you, I'm going to try and implement that approach.

But can you explain to me how the order of the items in each question gets scrambled? I don't think the issue is because of issuing multiple Append to File requests in quick succession, because it's not the questions that are out of order, it's the items in each question, and those are put together in a text variable before appending that variable to the file.

Intermittent errors are the hardest to debug.

Here are a variety of techniques you can try ...