write history to file immediately, for maximal synchronicity