Because both Gandalf and the Balrog are Maia, they share much of the same past. They came from the same place at roughly the same time. Though their lives took... different paths, wouldn't they already know each other? Like living for a Millennium in a small town, everyone knows everyone.
There's really no way of knowing if Olórin and the Balrog had met early in their lives; precious few writings focus on the Maiar at all, and basically none set in a period of time where these two might have interacted. It's certainly possible that they did, in the same way some of the Valar knew each other in the Timeless Halls, but we can't say for certain.
...But Gandalf may not have remembered anyway
It's never entirely clear how much Gandalf remembers of his life as Olórin; Unfinished Tales tells us:
[I]t is said indeed that being embodied the Istari had needs to learn much anew by slow experience, and though they knew whence they came the memory of the Blessed Realm was to them a vision from afar off
Unfinished Tales Part 4 Chapter II: "The Istari"
It's not impossible that Gandalf would have remembered, but it seems unlikely. Of all the things for him to remember, I wouldn't think a single co-worker from aeons ago would top the list.