This is a simple one,
The com-badge is real (data was wearing it when he entered), if he had thrown a holographic com-badge it would have passed through the wall as you say
As for Data knowing where the wall is:
A: He has shown in the 1st episode he knows how close the wall should be (until he suspected it was the holo-deck he hadn't bothered to work out where the walls position would be). It is entirely possible that that when the realized its a hologram, that he simple recalled every step they took since they entered: and where the wall should be in relation to that (he is an android and could remember that)
B: He knows how big the holo-deck is anyway, he could have thrown it hard enough to reach across the whole room, and the wall was just closer than that