As Hawkeye put it, doors opens both ways.
Is there any indication how Loki is able to trigger the Tesseract and get to the Earth in the first place?
In the end-credit scene of Thor, we can see that Loki was already influencing Selvig's mind.
Selvig: What is it?
Fury: Power, doctor. If we can figure out how to tap it, maybe unlimited power.
Loki: Well, I guess that's worth a look.
Selvig: Well, I guess that's worth a look.
We can't know how, but Loki made him to design the device and make it work so that it can open a door to let Loki teleport. It was planned near the end of Thor already.