only replace file if content has changed (avoids trigger of tools that listen to touches)

TBD: tests and cleanup