Presumably to have good long talks with other people
This is the full quote of what Gandalf says:
'I am with you at present,' said Gandalf, 'but soon I shall not be. I am not coming to the Shire. You must settle its affairs yourselves; that is what you have been trained for. Do you not yet understand? My time is over: it is no longer my task to set things to rights, nor to help folk to do so. And as for you, my dear friends, you will need no help. You are grown up now. Grown indeed very high; among the great you are, and I have no longer any fear at all for any of you.
'But if you would know, I am turning aside soon. I am going to have a long talk with Bombadil: such a talk as I have not had in all my time. He is a moss-gatherer, and I have been a stone doomed to rolling. But my rolling days are ending, and now we shall have much to say to one another.'
The Lord of the Rings: The Return of the King
(Emphasis mine) Gandalf had no other business helping in peoples' affairs, so what else could he do save perhaps having conversation with other folk, reminiscing about old times.
He does just that prior to his talk with Bombadil:
Here now for seven days they tarried, for the time was at hand for another parting which they were loth to make. Soon Celeborn and Galadriel and their folk would turn eastward, and so pass by the Redhorn Gate and down the Dimrill Stair to the Silverlode and to their own country. They had journeyed thus far by the west-ways, for they had much to speak of with Elrond and with Gandalf, and here they lingered still in converse with their friends. Often long after the hobbits were wrapped in sleep they would sit together under the stars, recalling the ages that were gone and all their joys and labours in the world, or holding council, concerning the days to come. If any wanderer had chanced to pass, little would he have seen or heard, and it would have seemed to him only that he saw grey figures, carved in stone, memorials of forgotten things now lost in unpeopled lands. For they did not move or speak with mouth, looking from mind to mind; and only their shining eyes stirred and kindled as their thoughts went to and fro.
It isn't farfetched to say that he met with other Elven folk, maybe Cirdan and fellow Istari Radagast, to talk about what was in Middle-earth.
Visiting the Shire
We do know at one point before the end Gandalf visits the Shire to invite Merry and Pippin to the Havens. (Thanks @Galastel in comments)
'You tried to give us the slip once before and failed, Frodo.' he said. 'This time you have nearly succeeded, but you have failed again. It was not Sam, though, that gave you away this time, but Gandalf himself!'
'Yes,' said Gandalf, 'for it will be better to ride back three together 'than one alone. Well, here at last, dear friends, on the shores of the Sea comes the end of our fellowship in Middle-earth. Go in peace! I will not say: do not weep; for not all tears are an evil.'
Or just having a last look at Middle-earth
He is going back to Valinor, and we will never know if he returns to Middle-earth again. After over a thousand years in the land, he may just want to walk around the countryside, wondering what would have happened to the land had Sauron won, or thinking about his labors throughout the years. We wouldn't know.