We learned previously that all of the letters of tefillin and mezuzot must be written in the order in which they appear in the Torah. This principle is known as "kesidran" and is derived from the verse, "vahayu hadevarim"- they should be written as they appear. Therefore, it is especially important to purchase tefillin and mezuzot from a God-fearing sofer, as it is impossible to check whether the sofer adhered to this law, and we rely solely on his credibility.
What if a letter is written incorrectly, such as a "yud" which is written without its bottom right leg, or a "shin" written with only two legs, or any other letter written incorrectly. If the sofer has already continued writing, he may not go back and rewrite the letter; this is a classic example of "kesidran." So much more so if the original letter looks like a different letter, in this case, since the letter looks like a different letter, going back and correcting the letter is a violation of the principle of "kesidran."
Interestingly, if the sofer wrote a letter which is formed from two letters, such as the letter "mem petuha," which is formed from a leter "nun" and a letter "mem," some sofrim writes the "nun," and then the "vav," in the left to right order. However, even if a sofer wrote the "vav" on the left side, and then the "nun," on the right side, that is not considered to be a violation of "kesidran," as he is writing the same letter.
Finally, the law of "kesidran" applies only to a complete letter, and not to half a letter. Therefore, if a sofer writes half of a letter, and then he returns to correct the letter before it, that is not considered to be writing out of order since the half of a letter is not considered to be a letter. There are Poskiim who are strict and insist that the half letter should be erased before fixing the previous letter, but bedi’avad, we rely upon the lenient view.
Summary: When writing tefillin and mezuzot, the letters must be written in their proper order. However, if the sofer writes a letter with the intention that it should join another letter to form one letter, the principle of "kesidran" does not apply, nor does it apply if one wrote only part of a letter and he wishes to go back and correct the previous letter.