'Not alone,' said Legolas. 'We think that Sam went with him.''Did he!' said Gandalf, and there was a gleam in his eye and a smile on his face. 'Did he indeed? It is news to me, yet it does not surprise me. Good! Very good! You lighten my heart. You must tell me more. Now sit by me and tell me the tale of your journey.'
As for which close call Gandalf was talking about, I am not sure... A quick search hasn't found the quote, but there is a sequence in the book where a winged Nazgul is near Frodo and suddenly veers away... There is another time when Frodo senses the eye searching for him, getting closer and then it rather suddenly turns away. I will look for it on our next run through the Two Towers when we start up the Green Dragon again.
Ahh! See, there I go being hasty again! HROOOM HOM!
That scene is in "The Fellowship of the Ring", chapter, "The Breaking of the Fellowship". Frodo is on Amon Hen, in the Seat of Seeing, just as the previous poster said.