According to TMP Starfleet doesn't recommend using warp drive inside a solar system (although it's a rule that seems to be ignored even in non-emergency situations by the time of TNG that was probably just for the sake of a cool visual).
Scotty did mention that the engines hadn't even been tested at warp power. Probably a good idea to test them as far away from traffic and planets as possible. If the wormhole had formed near Earth who knows what would have happened.
It was to set up a cool effect but at least there was some foreshadowing that something could go wrong.