Did Gandalf know there was a Balrog in Moria? If so, did he go there on
purpose to confront it, reasoning that someone would have to eventually?
Yes Gandalf was aware that a creature of the ancient world dwelled in the mines
of Moria. Gandalf being an Istar; one of the servants of the Valar knew all
about Balrogs, the Creatures of Morgoth (a Vala that was the first Great Evil,
and the one that Sauron Serves) read the SIlmarillion and unfinished tales for
the history of the Istar, Maiar, and
Vala.