Don't rewrite state file if state didn't change.

It's required to prevent looping on --exit-on-no-events