Already in Old English the Old English preposition tō 'to, into' (and other senses) gave rise to an adverb tō 'besides, also; moreover'. In normal speech the preposition was generally unstressed, and as a result the vowel tended to be reduced from [ō] to [ɔ] or perhaps even to [ɑ], since the spelling ta actually occurs. Similarly, in present-day English the preposition to in connected speech is usually unstressed and reduced: ‘I went t[ə] the store’, not ‘I went t[ū] the store’. The Old English adverb, on the other hand, was likely to receive stress in connected discourse and therefore to retain the full vowel: [tō].
This situation continued into Middle English. However, during the later Middle English (and extending into the Early Modern English) period the pronunciation of English long vowels changed dramatically. These changes are collectively known as the (English) Great Vowel Shift (GVS). (See these pages for more information.) In particular, [ō] shifted to [ū], the vowel in present-day English too. At this point the preposition was usually pronounced something like [tə] in connected speech, while the adverb was [tū], pretty much as in present-day English. This greater disconnect between the two pronunciations tended to obscure the historical relationship between the preposition and the adverb.
Middle English spelling was of course not standardized, but vowel length was often indicated by doubling. As a result, words with the vowel [ō] were often spelled with oo, though this seems not generally to have occurred with the adverb in question. After the GVS, words spelled with this oo were pronounced with [ū], and as spelling became increasingly standardized, oo was more and more associated with the vowel [ū]. Since the adverb had for some time been clearly distinguished from the preposition in pronunciation as well as in sense, there was no real reason to maintain the historical connection, and too, a spelling that represented the actual pronunciation of the adverb, gradually displaced the older to spelling.