Added check to client-side file writting to make sure it doesn't add extra data to the end of the file