In the Uva L'Tziyon, after the kedusha desidra, we read "בָּרוּךְ הוּא אֱלהֵינוּ שֶׁבְּרָאָנוּ לִכְבודו. וְהִבְדִּילָנוּ מִן הַתּועִים. וְנָתַן לָנוּ תּורַת אֱמֶת." ("Blessed is He, our God, who created us for His glory, separated us from those who stray, gave us the Torah of truth..." according to the Artscroll siddur)
I quick look in Bar Ilan (and a look through the Beurei Hatefilla site) shows no particular source for the idea of being separated from the to'im. A search of the word To'im turned up some commentaries who used the word:
The Lekach Tov says, "ולא כמו שאומרים התועים עצרת לאחר השבת" seeming to point to those who reject the oral law in computing the date for Shavu'ot, so the "Torah" in the following line would be the Oral Law.
In his Seder Pesach, Amram Ga'on writes "ותלמידי ענן ירקב שמו, אבי אביו של דניאל, חוט המשולש ברשע ובמינות, שאמר לכל התועים והזונים אחריו, עזבו דברי משנה ותלמוד ואני אעשה לכם תלמוד משלי" referring to a group that also rejected Oral Law as taught by Chazal (though they replaced it with their own Talmud).
The Ibn Ezra on Daniel 11:30 writes, "One is surprised by Sadducee sages who interpreted this as referring to the future. They said that the sanctuary is Mecca, around which the Ishmaelites circle. and they put aside the daily sacrifice the five prayers (the Salat). and they set up the abomination, idolatry. And they are the mistaken. As is it may be that miqdash/sanctuary refers to Jerusalem alone." Though I can't tell if he means that the "they" is the Sadducees or the Ishmaelites.
The Abarbenel on Bereishit 15 writes, "כדי לצרוף את בני ישראל ולהבחינם בקרב מצרים התועים לראות היעמדו באמונתם כמו שהיה ראוי לצרוף ולזכך העם שהיה עתיד לקבל התורה ולרשת את הארץ ולהדבק בו" which is either pointing to a faction among the Israelites or among the Egyptians but not about the Oral Law.
The Alshich (Mishlei, 3:1) writes "הנה עד כה הבדילנו מן התועים ומפתויי החטאים וילמדנו להקשיב לחכמה אזננו" which seems to point to a generic "sinners" while the Apiryon (I hope I have the name right) on Lech Lecha uses the word in reference to those who deny divine creation of the world (לאפוקי דעת התועים ואומרים שהכל הוא בטבע). He uses it in a variety of other places to refer to those who deny Hashem and His power in the world.
So who exactly are the to'im and how are we separated from them? How did this idea become crystallized in this phrase and become such a central part of our prayers? The Aleinu seems to echo some of these ideas but doesn't use the word "to'im."