Earle had long been fascinated with the prospect of harnessing the Black Lodge powers, but it wasn't until the events in Twin Peaks that Earle became privy to the location of the lodge's gateway.
There is discontinuity in the script or editing of episodes 27 & 28. The Ep 28 scene where Earle overlays the owl cave glyph on the TP map should have occurred immediately following Earl's interrogation of Major Briggs in episode 27. Meaning, it is in Ep 27 that Earle discovers the location of the lodge's gateway, and we can imply that he immediately travels to it.

This falls into sequence with the scene of Bob emerging from the gateway at the end of this very episode. Here it is actually Windom Earle emerging from the lodge, but in Bob's image. Notice that Earle warily reaches out from the exit, as he is not yet seasoned in navigating into and out of the gateway. Upon his successful exit from his first visit, he vociferously proclaims "I'm out".
Perhaps while he was in the black lodge for this first time, Earle transacted with Bob and agreed to become Bob's host.
When we next see Earle in the following episode, he momentarily takes on the appearance of a Black Lodge dweller (whitened face, blackened mouth), perhaps the image of a Dugpa.
This all is further substantiated in the final episode; in the dark of night and dragging Annie along, Earle does not seem to have a problem locating the lodge gateway and making an entrance. His approach and demeanor indicate that it is not his first time being there.