In conference with General Lee after the first day, Longstreet did want to move around the Union left and take up a position between the Army of the Potomac and Washington and then wait for the U.S. to attack. This is one of the most endearing 'what ifs' of the battle, but if one looks at the bigger picture you can see that Lee was right and Longstreet was wrong.
In the first place, the road network would not have permitted it easily. Roads flowed into Gettysburg like spokes on a wheel. The Army of Northern Virginia would have needed an east-west route for their supply train. No such route existed. Lee could have moved back in the direction he came from, but moving the thousands of wagons in his trains east and south towards Washington wasn't feasible.
In the second place you have to remember that Lee was in contact with the enemy. Disengaging and then moving east would have exposed the army's flanks to attack. Again, the only option immediately available to Lee was to go back in the direction he came from. That would have left the Union army between him and D.C., able to maneuver and block him on ground of their own choosing, possibly on worse ground than Lee was already facing. Then again there was the logistical problem of reorganizing the troops engaged in the battles of the first day, getting the army and the logistics turned around and headed back up the road, all in the face of the Union Army. Not an easy task, and one that left the confederate army vulnerable during the attempt.
Any shift left the confederate line of retreat vulnerable. Lee used the Shenandoah Valley to protect his flanks and guard his intentions while moving North. Manuevering around the Union Army put them between him and his road he needed to go back home in the event of an emergency. No general would willingly do that.
The long and the short of it was that Lee was right. The enemy was there, and he would fight them until he whipped them, or they beat him. He had no other choice once the battle was joined, any other course of action presented even more dangers than a knock down-stand up fight with Meade. Lee quite properly attacked on the second day, he had no other choice.