In Lord of the Rings, Gandalf has returned because he has learned that Black Riders are searching for a 'Baggins' with a ring. This information was obtained when Sauron captured and tortured Gollum/Smeagol and learned that someone named Baggins, took it from him.