To write (save) the current file only if the file has been modified you can use the ex commands :up r :update.

The difference between this command and :w is that :w will write the file even if it has not been modified. This command is also similar to :x, :xit, :exit, and :exi, but will not quit the window after writing the file.

Further Reading

:h :up :h :update :h :w :h :x :h :xa :h :xit

More Gifs