hwrt/utils.py: refactoring (tempfile; splitted long function)