I would say that doing this in close is better, keeping all things at one place. Also, even if close fails and write happened, next open is anyways incrementing the counter, so value is not changing.