The Shulhan Aruch (32:20) teaches that the sofer must be especially careful regarding haserot and yeterot, i.e., certain words are spelled with a "vav" (yeterot) and others without a "vav" (haserot). In addition, the sofer most be careful not to write the "final letters," i.e., the mem sofit, nun sofit, tzadik sofit, peh sofet and chaf sofim in the middle of a word. The Mishna Berura (71) writes that in this case, the letter is considered to be invalid. Similarly, if the sofer wrote a regular letter at the end of a word, that too is invalid.
What if a sofer, while writing tefillin, forgot a letter? In this case, due to the principle of "kesidran," which teaches that the letters of tefillin and mezuzot must be written as they appear in the Torah, the sofer would not be allowed to return and fill in the letter. What if a sofer inadvertently added a letter? For example, if the sofer writes the word "leavotecha," which is supposed to be written without a "vav, with a "vav" after the "bet"? In this case, the sofer should erase the "vav." However, since he has now left a gap in the middle of the word, making it appear as two separate words, the sofer should lengthen the "bet," on its top and bottom, and then it will look like one word.
However, this is not always possible, For example, when writing the word "se’or" which is spelled "sin", "alef" and resh," if the sofer added a "vav" after the "alef," there is no way to extend the "alef" or the "resh", and in this case, the letter "alef" and "resh" should be thickened, and then the letters will appear to form one word.
Finally, if the sofer wrote the same word twice, he should erase the second word. Although there will be a gap between the words, the halacha teaches that if the gap is no longer than the space of nine letters, it is valid. However, it is preferable to avoid leaving a gap. Therefore, if the sofer wrote the word "veshameru" twice, he can erase the second "veshameru," or, he can erase the final "vav" of the first "veshameru," and then second veshsameru until the "vav," leaving two words – "veshamer" and "u." In this case, the sofer can lengthen the last letter of the first word, i.e., the "resh," until it reaches to the second "vav," which solves the problem of a gap, and the order in which the letters were written (kesidran).
Summary: The sofer should be especially careful and should not add, or omit a letter. In certain cases, there are ways to correct this mistake, without erasing an entire word, or without erasing an entire passage and beginning again.