In the context of the writing of a Get (writ of divorce), the Torah writes, "Ve’chatab Lah" ("He writes for her"). The Gemara (Gitting 20) infers from this verse that the words of the Get must be written, and not formed by chiseling – "Ve’chatab Be’lo She’hakak." This means that if the scribe was preparing to write the text of the Get, and some ink spilled, he cannot form a letter by scraping away the ink around the shape of the letter. A letter formed in this fashion was not "written," but rather indirectly formed through chiseling, and the Get is therefore invalid. Forming letters by removing excess ink is known as "Hak Tochot."
This applies as well to the writing Sifreh Torah, Mezuzot and Tefillin. All the words must be formed through the direct writing of the letter, and not by chiseling the ink around the area to form the letter. Thus, for example, if a Sofer mistakenly wrote a Dalet instead of a Resh, and he scrapes off the protrusion from the top line to form a Resh, the Tefillin (or Sefer Torah or Mezuza) are invalid for use. Even though the Resh is formed perfectly, the Tefillin are nevertheless Pesulot because the letter was not written directly. The Sofer must therefore erase the incorrect letter and then write a Resh. A similar example would be a Sofer who mistakenly wrote a Bet instead of a Chaf. Once again, he may not simply scrape off the excess ink that turns the letter into a Bet; he must erase the Bet and write a Chaf in its place. For that matter, if a letter was written properly but then some ink spilled into the area inside the letter, it must be erased and rewritten; the Sofer may not erase the ink to form the letter. This Halacha, along with these examples, is mentioned by Maran in Shulhan Aruch (Orah Haim 32:37).
As we’ve said numerous times, it is imperative to purchase one’s Tefillin and Mezuzot from a Sofer who is proficient in the relevant Halachot and also honest and G-d-fearing. When a customer sees the Resh in his Tefillin, even if it looks perfectly valid, it may have been a Dalet which was then formed into a Resh, in which case his Tefillin are invalid for use. One must ensure to purchase Tefillin from a Sofer reputed to be both a scholar and G-d-fearing person, who can be trusted to write the Tefillin properly in accordance with all the pertinent Halachic details.
Summary: The letters of the Tefillin must be actually written, and not formed indirectly by scraping off the ink around it. For example, if a Sofer mistakenly wrote a Dalet instead of a Resh, he must erase the letter and write a Resh, rather than scraping off the protrusion from the top line to change the Dalet into a Resh.