Improve handling of temporal directories when running tests