The same magic that makes James' wishes come true - traveling to New York, having a large group of friends that also act as a caring, surrogate family - also brings to life his fears. The mechanical shark spits out the same plates of disgusting fish heads Spiker and Sponge fed him, and threatens to prevent his escape to a better life just as they do in the film's conclusion.
Also, when James first meets the bugs in the film, only Miss Spider knows his real name (the others didn't know, or thought that his aunts' nicknames for him was his name.) It might be overlooked - however, when you find out that James befriended Miss Spider and saved her from his aunts in the beginning it makes sense that she knows his name. She would have heard his "I Am" Song, after all.
When the giant peach impales itself on the Empire State Building, James was inside. He's lucky he didn't get stabbed, too!
And on that note, what do you think the bugs were thinking when the peach fell? As far as they knew, the little boy they loved as their own could very well be seriously hurt or dead. One can only imagine that they were beyond relieved when they were all reunited, but still.
A bit of rather sad Truth in Television. Notice that when James first meets the bugs in the peach, he tends to shy away or tense up when they get close. Why? Because he's used to being beaten by his aunts and is afraid that these strange adult figures might hit him like his aunts do, which is typical behavior for an abused child. However, this behavior vanishes as the movie goes on, showing that James has come to trust his new friends and knows they'd never hurt him.