minor refactor
Use temporary files to prevent IO race conditions.

Refer to #260.