remove redundant code in TemporaryFile and add test