Wrapped chdir in a try\finally block so cwd would always be restored

Signed-off-by: Michael Welter <michael@cetoncorp.com>