Write buffer to file only when expected length is greater than file size.