Improved directory and file handling for unit tests.