Don't replace the instance

Instead of completely replacing the os.environ instance, use clear() and
update() to restore state on the original instance.

Suggested by njoyce and robertkluin.