in phrase to the nines "to perfection" (1787) first attested in Burns, apparently preserves the ancient notion of the perfection of the number as three times three (such as the nine Muses).
[T]he Book of St. Albans, in the sections on blasonry, lays great stress on the nines in which all perfect things (orders of angels, virtues, articles of chivalry, differences of coat armour, etc.) occur. [Weekley]
No one seems to consider that it might be a corruption and misdivision of to then anes, literally "for the one (purpose or occasion)," a similar construction to the one that yielded nonce (q.v.).