In The White Rider, chapter 5 of The Two Towers we are shown the meeting between Gandalf and Aragorn et al. They see an old man in dirty grey rags and jump to the conclusion that it is Saruman (after all, they know that Gandalf is dead, so who else is it going to be?). Gimli urges Legolas to shoot him, but Aragorn and Legolas refuse to kill an old man who might be entirely innocent.
Gandalf approaches the three and speaks in riddles. Eventually:
"Saruman!" cried Gimli, springing towards him with axe in hand. "Speak! Tell us where you have hidden our friends!..."
Gandalf blocks the attacks by magic, and is suddenly recognised by the party. Aragorn wonders "What veil was over my sight?"
"Gandalf", the old man repeated, as if recalling from old memory a long disused word. ... "Yes, you may still call me Gandalf," he said, and the voice was the voice of their old friend and guide.
So it seems that the film merely tried to represent this scene, albeit in a way that compresses several minutes of conversation and argument into a few seconds. In particular it seems from the book that Gandalf's face and voice were unrecognisable until after Gimli's attempted attack.
Also, part of the return of Gandalf is that he is now "Gandalf the White". In the book this does not become plain until later, but in the movie we see Gandalf wearing a shining white cloak from the beginning of this scene. Since the wizards were previously Saruman the White and Gandalf the Grey this was another reason for Aragorn et al to believe that they were seeing Saruman.