Trim newlines and backspace at the end of the filename