Because Bilbo is in a number of different caves in J. R. R. Tolkien's The Hobbit, I'm going to assume that this question refers to the time in which Bilbo finds himself in a cave, alone, after he is separated from the company as they flee from their captivity in chapter 4: "Over Hill and Under Hill." During the escape, the goblins sneak up on the dwarves and Bilbo falls off of Dori's back. He is knocked out, and when he comes to at the start of Chapter 5: Riddles in the Dark, he finds himself alone in the dark.
He cannot find his matches, but when he pulls out his sword "[i]t shone pale and dim before his eyes" (116). Immediately, he knows that goblins are somewhere in the vicinity, because the sword glows blue when they are near. No goblins find him at this moment, but their proximity allows him to use his sword as a dim light to guide him. This is useful, because he is about to meet Gollum for the first time, and given that the creature can see in the dark, Bilbo will need whatever light he can get.