prepare_tempfile_object(): new function, extracted from create_tempfile()