In both the movie and the book, Ender spends quite a lot of time playing a fantasy game (though the book goes into a lot more detail). In the book, the game is described as a highly sophisticated psychological analysis engine. The giant scenario is meant to screen out suicidal tendencies; the cadets are supposed to stop coming back after a while. Ender's repeated returns to the area are disturbing to the brass at first, but when he gouges out the giant's eyes and gets past the scenario, they are totally shocked. The game begins going in completely new directions with him, adapting itself and growing to fit his needs. At one point, it manages to grab pictures of Peter and Valentine off the internet, which freaks Graff and co. out even more, since it's not supposed to be doing that. Eventually, it is revealed that the Formics have been communicating with Ender via the game. That's why he found the egg in the castle-like structure from the game.
The major difference from the movie is that the Formics hid it on a totally different planet from Eros. The humans didn't get there until after they were already quite sure the Formic species was extinct. The structure was also recognizable by Ender and Ender alone. They positioned this whole thing just far enough away from a reasonable settlement site so that it would not be thoroughly examined, but close enough that Ender could plausibly find it if he were looking. Since the structure has a natural(ish) appearance, nobody else would have noticed, except perhaps for Graff and the other adults who had been monitoring Ender in Battle School.
At this point, Ender is an adult, renowned and beloved by most of the population. He is helping scout a potential sister to an existing colony (on the same planet), when he encounters the structure. He is trusted enough that he is able to more or less unilaterally move the second colony elsewhere without anyone seriously questioning it, and he begins searching for a homeworld for the Formics. That leads into Speaker for the Dead and the rest of the main book series.