Refactor #tmp_directory into helper module