The gemara (Menachot 32b) teaches that there is a Halacha LeMoshe MiSinai (an oral tradition given to Moshe Rabbeinu) which requires a sofer to etch lines or grooves into the parchment, known as ‘sirtut’ (‘scoring’), to ensure that the sofer writes the letters in a straight line. The gemara states that this law applies to Sifrei Torah and mezuzot. Sifrei Torah and mezuzot written without these lines are invalid (pasul).
The Rishonim discuss whether tefillin also require sirtut? Rambam (Hilchot Tefillin, Mezuza V’Sefer Torah 1:12) rules that tefillin do not require sirtut (they do not need ‘scoring’) because they are "covered" (mehupin). In other words, since the Sefer Torah and mezuzot are visible, sirtut is required to ensure that they are written nicely. However, we are not as concerned with the appearance of the parshiot of the tefillin, since they are kept inside of the batim (boxes), and therefore they are valid even if written without sirtut.
Interestingly, Maran (Shulhan Arukh, Orah Haim 32:6) rules that although tefillin do not require sirtut, the sofer must make a line above the first row of words. The Aharonim explain that this is due to a general principle, found in Gittin 6b, which requires sirtut for any three – four biblical words written on parchment (klaf), and not related to the requirement of sirtut.
The Kaf HaHaim relates that there was once a sofer in Bagdad who wrote tefillin without even scoring the top line of the parchment. They asked the Ben Ish Hai whether these tefillin are valid. The Ben Ish Hai ruled that although preferably the sofer should have etched a line in the top of the klaf, b’diavad the tefillin are valid. Hacham David, in his Otzarot Yosef, adds that in this case, a sofer should still add a sirtut to the top line.
Nowadays, all tefillin are written with sirtut throughout the entire text. In fact, the sofer usually receives the klaf from the manufacturer already ‘scored’.
Although the Sifrei Torah, tefillin and mezuzot must be written lishma, i.e., with the proper intention, there is no need to ‘score’ the parchment with the proper intention. In fact, nowadays machines often etch the lines into the parchment.