You’re right that it goes way back, but the actual term “twin flames” is surprisingly recent. Not Taylor Swift and MGK recent but not that much further back in the scheme of things.
Elizabeth Clare Prophet is credited with popularizing it in the 1970s through her Church Universal and Triumphant teachings. She wrote extensively about it and made the distinction between twin flames (one person, same soul) versus soul mates (multiple possibilities).
Buuut the concept behind it has roots going back to ancient Greece.
Plato’s Symposium from around 385 BCE has this myth where Aristophanes describes humans originally having four arms, four legs, two faces. Zeus split them apart and now everyone searches for their other half. That’s probably the oldest Western source we have that sounds like twin flames.
We talk about this a lot as the “history of twin flames” but Plato actually presented this as satire, and he later criticized the idea as philosophically immature. But it has stuck in cultural consciousness for over 2000 years. Jewish Kabbalah also has something similar with the concept of bashert - the idea that souls are divided before birth and destined to reunite. That tradition is genuinely ancient, developed through medieval Kabbalistic teachings but rooted in the Talmud from around 500 CE.
There are references in the Bible and throughout quite a bit of history. Even now, it shows up in our pop culture, whether using the term or not.
I don’t know if anyone really knows the proper origin of twin flames. It seems to be scattered around humanity everywhere. My guess is that even if previous writings and learnings were lost to time, we always come back to them through the experiences of those who go through the journey.