I exported users in CSV format with the Admin > Users > Export button. While the file is substantially valid, it’s rejected by many tools (like miller or parsing libraries) because not all lines have the same number of commas/fields. It looks like your exporter omits commas when last fields have no value. While this looks reasonable, it looks like it breaks the formal specification of CSV files.
Discourse version: the one used as of now in your hosted forums
That sounds like a bug. I’m assuming the issue with the users CSV file is happening when no group_names field is set for a user. I can reproduce that with a CSV file that contains staged users. Is this where you are seeing the problem?