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.
In the book, film, and musical, James is willing to risk his life to help Centipede (he falls off the peach in both the book and musical and goes after a compass in the film) despite being a young child. Why? Because he's already lost his mother and father and doesn't want another family member to die.
This troper always found it a little odd that in the book, James was the only one to go after Centipede when he falls into the ocean. However, there is a very good reason: James is the ONLY one of the group who can swim.
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.
In the film, Miss Spider mentions that she never had any friends before meeting James; according to her, it's because bugs naturally fear her. While that probably is the case, it should also be noted that she lived in Aunt Sponge and Aunt Spiker's house. Both of them despised bugs and killed any that they saw; hell, they even tried to kill her. It's likely that even if Miss Spider had met bugs that were friendly to her, they were killed by the aunts shortly after.
If the aunts killed James, accidentally or otherwise, no-one would ever know. They're completely isolated up there and the aunts didn't let James out while the sightseers were present, so it's very likely that no-one even knows there's a little boy on that hill.