Don't use TemporaryFile in try_write

TemporaryFile tries thousands of times before if fails, making it really
slow. Just use open and unlink.

Fixes #896.