Added checks to avoid updating the file when there is no change.