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.
32I’m pretty sure right before the whole “YOU SHALL NOT PASS!” thing Gandalf did like a little nod and said “Hey Bill.”– Paul D. WaiteApr 12, 2016 at 14:09
3@PaulD.Waite Bill the Balrog and Will the Wizard / Met in a darkened mine. / Old foes in the days before Arda, / They fought to the death of both.– Rand al'Thor ♦Apr 12, 2016 at 14:32
6Corrupted from "This is my PAL BILL ROGG"– Chris B. BehrensApr 12, 2016 at 15:41
Didn't the fire spirits go directly towards Morgoth?– ibidApr 12, 2016 at 16:08
1I think I've always taken it for granted that the Balrog, when we saw it in Moria, looked very different from whatever its appearance had been thousands of years earlier, "in the good old days." So even if Gandalf knew any given Balrog had to be "a fellow Maia gone bad," he wouldn't necessarily be able to tell which one he was meeting that day. And Gandalf too may have looked very different from how he used to appear in "the good old days." So I'm not surprised that they didn't greet each other by name as soon as they saw each other in Moria.– LorendiacNov 19, 2016 at 3:29
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.
2Also, considering how few balrogs there were (less than 3-7), it's possible that he knew of him, even if he didn't personally know him.– ibidApr 12, 2016 at 18:06