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.
It seems a bit random to have a music number about all the weird things the bugs have eaten, but it becomes Fridge-Heartwarming when one realizes it's a bonding moment between James and the bugs. James knows what it means to have nothing but gross food, like those fish heads his aunts served him. The bugs are sharing what they've had before, and it's no better. And the song is concluded by both James and the Bugs' mutual understanding that good food (namely the peach) is something to be very grateful for.
What's more, the bugs most likely have had their fair share of eating less-than-great food, because of how Spiker and Sponge's garden is relatively a barren wasteland for them.
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.
The police in New York City opted to tell the crowd to flee while not racing to the aunts to stop them from murdering James. To be fair of them, there were just a few seconds between the aunts' Villainous Breakdown/Moral Event Horizon, and the bugs coming down to attack them. Any longer, and the police would've shot the aunts dead, saving James and probably everyone in New York. They just needed to get people out of the way first in case of stray bullets, and James was at a safe distance from his monster aunts to give the police enough time to shoot them.
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.