Implementing atomic operation for stats file

There is some possibility of overwriting `path + '.tmp'` file in dump function if you set `--dump-stat-interval` to short interval.
This patch fixes the issue by implementing atomic file operation.