printng - fix tmp file handling, close files
(cherry picked from commit 9117c88601f5e231df26487794eaf4d38075b5f3)