I started looking into that. From the paper here (one of the co-authors is an old professor of mine!), it sounds like you could shift the orbit of the Earth by about 30 miles by sending a massive asteroid on a close pass. They're thinking more about the very long term, shifting Earth out to the orbit of Mars as the Sun heats up later in its lifetime, and for that, it sounds like it could work well, sending an asteroid flying by every few thousand years over a very long time period. But for the kind of emergency move we need in this scenario, you'd still need at least a few hundred passes (just how far away does the Earth need to be from a Mars-sized impactor before the tidal forces from a near miss aren't just as effective in destroying life as a direct hit would be?), which might be hard to orchestrate in the very short time frame available. I also tried to do some order of magnitude calculations on building mass drivers to start launching rocks at high speed to shift the Earth's orbit, and again it appears to fall well short of what you'd need.
Conserve energy. Commute with the Hamiltonian.
The Mars-sized thing has much less mass than Earth, so it would be easier to nudge it than Earth. Also, we would care less about any violent side effects of the nudging process--like huge impact craters.
There may be an interesting alternative, though. There's a Moon-sized thing available which is much less massive than the Mars-sized thing. It might be easier to nudge it so that it gets in the way of the Mars-sized thing. This will still involve a stupendously violent shower of impactors that bombard Earth...and over a long term, also, as most of the ejecta ends up in a huge torus of NEAs around 1AU from the Sun.
But this reduces the problem from space habitats to mineshafts...
Heck, given the OP's premise, it is hardly even necessary to have an artificial energy source. A Mars sized world crashing into Earth would not render the solar system uninhabitable. The sun would still shine, so we could use O'Neill's and other space habitats as is.
We could save so much more if we decide to stick in solar system compared to trying to get to another star.