Remove trailing whitespaces before write buffer