Added method to clean out remporary directory

Moves code to clean up temporary directory into it's own function, as requested by #3324. Should there be a test for this? I couldn't find any testing of the file utilities but maybe I wasn't looking in the right place.