Add replace.file(filename, new contents)

This function first backs up the existing file and then atomically
replaces it.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>