Refactor #tmp_directory into helper module
Cache temp directory by prefix
Extract temp directory removal into helper module