TO A T - "We use this expression very commonly in the sense of minute exactness, perfection; as, the coat fits to a T; the meat was done to a T. It is easy to dismiss the origin of the expression as, I am sorry to say, some of our leading dictionaries do, by attributing it to the draftsman's T-square, which is supposed to be an exact instrument, but the evidence indicates that the expression was in common English use before the T-square got its name. 'To a T' dates back to the seventeenth century in literary use and was undoubtedly common in everyday speech long before any writer dared to or thought to use it in print. But it is likely that the name of the instrument, 'T-square,' would have been in print shortly after its invention, yet the first mention is in the eighteenth century. The sense of the expression corresponds, however, with the older one, 'to a tittle,' which appeared almost a century earlier, and meant 'to a dot,' as in 'jot or tittle.' Beaumont used it in 1607, and it is probably that colloquial use long preceded his employment of the phrase." From "2107 Curious Word Origins, Sayings & Expressions from White Elephants to a Song and Dance" by Charles Earle Funk (Galahad Books, New York, 1993).
Also see http://worldwidewords.org/qa/qa-toa2.htm