MMP: write to temporary file first and then rename

In order to avoid data loss because of full disks or other storage
failures write a temporary file first, rename current file to backup
file and rename temporary file to current file.

Closes #26.