We usually assume l'halacha that both a mezuza and tefillin must be written in order, which means that if a p'sul is found in an earlier letter, the only way to fix it is to scratch out every letter until the end of the entire mezuza and then rewrite it. That is why we generally are unable to fix tefillin and mezuzos when they have a p'sul, to the exclusion of a sefer torah on which there is no din of כסדרן and is not required to be written in order.
The gemara talks about converting a sefer torah into a mezuza or tefillin. The only issue that the gemara has with this is that a sefer torah has more kedusha than tefillin and mezuza, and one cannot downgrade kedusha. From this the gemara derives that there must be some material on which a sefer Torah can be written, that would be acceptable for tefillin and mezuza (Tosafos holds that for sefer torah we not only permit the 3 forms of parchment - גויל, דוכסוסטוס , קלף, but we even permit the use of paper. Tosafos points out that the yerushalmi rejects the use of paper).
Tosafos questions how one would convert a sefer torah into a mezuza since a mezuza requires the parsha of והיה אם שמוע to be written immediately after שמע, yet in a sefer torah they are far apart. One of the possibilities that Tosafos suggests is that if והיה אם שמוע happens to be written on the top of a column, one can cut it out from a sefer torah and write the parsha of shema on the margin above. The problem with this that Tosafos does NOT address is that this would seem to be a violation of כסדרן since the parsha of והיה אם שמוע will be written prior to the writing of שמע?
The Taz (Y.D. 190) writes that we see from this Tosafos that the requirement of כסדרן by mezuza does not demand that the parshiyos be written in order, just that within each parsha each word and letter is written in order. The Shach in Nekudas HaKesef disagrees and is madchik in Tosafos to explain that even Tosafos requires כסדרן on the parshiyos.
The Chasam Sofer (teshuvos y.d. 282) asks that for tefillin we learn from והיו that they need to be written in order. Although there is room to reject the mechilta that applies the din of כסדרן to mezuza, and hold that there is no din of k'sidran by mezuza. The compromise requiring the letters and words to be k'sidran but not the parshiyos doesn't make sense because by tefillin we require even the parshiyos to be written in order?
The Chasam Sofer has a fascinating approach. He holds that the din of כסדרן is not focused on the order. Rather it is a din that when the parsha of והיה אם שמוע is written, it must be written with the kedusha of mezuza. The way this is accomplished is by having the parsha of שמע proceed it, it is considered to be written with kedusha of mezuza. Therefore, if והיה אם שמוע is written before שמע in general, it would be passul because the parsha of והיה אם שמוע is written without kedushas mezuza. However, when והיה אם שמוע is written within the sefer torah itself, it is written with kedushas sefer torah which is a greater kedusha than mezuza. Therefore, specifically in the case where והיה אם שמוע is written within the context of a sefer torah and assumes kedusha through the sefer torah, can we allow shema to be written afterwards on the upper margin.