The grade export code is not properly encoding or escaping line returns, which are commonly used by instructors when entering extensive grade feedback.
It's also not putting quotes (") around fields in csv format, which the standard trick for handling field content that may contain line breaks.
These problems make it impossible to use the exported file without first fixing the scrambled columns/rows. Otherwise, Moodle will fail a "round trip" export/import of course grades. I would consider that to be an essential test of the gradebook export/import codebase, and one of the most common use cases.
Some possible fixes:
– if line returns are found in grade feedback, warn the user that they will be replaced with spaces if you export as text
– put quotes (") around all fields when exporting as CSV *
– escape line returns with an backslash, or encode them as html entities
*This is what MS Excel does handle line breaks in spreadsheet cells. It works perfectly to export a spreadsheet as CSV, and reload.