Mimic actual temp dir detection during tests

This fixes a bug where upon second run of the tests, the temp files would always
be used instead of cleared as desired.