restore current directory after register_shutdown_function callback.

in

While I can't point to any core bug this causes, and this can be solved in contrib, I think that we should save and restore the current working directory because this is a known problem with register_shutdown_function (see comments in thread) and a potential hazard for many people.
I just spent several hours tracking this down from devel, to our stream wrappers, and finally to the fact that the current-working-directory was changed to /. This is a very easy fix in core, very few extra lines, and will probably save other developers lots of time.