Remove trailing whitespace on write