Implementing atomic operation for stats file