Fix state file persistence

This ensures the state persists correctly when monitoring more than one file.

Currently it will wipe the state on each flush and only persist for files involved in that flush. This makes it keep the last state and just update it.