It's not as lucky as you think. We formed from the same cloud that made the sun, so the material that made the earth was already in a fairly stable orbit.