replaced handmade solution with tempfile call to create /tmp file