Safer Cache saving

Create tmp file and then move it to destination. Avoids corrupt files during write