Flushing to file to force writing of header and before closing. This causes enough latency to avoid the duplicate header entry. Fix for #297