Save files atomically

This fixes #28.