I want to suggest that you first combine all your CSVs into a single CSV, make sure that's correct, then convert the single CSV to XML:
- you'll be able to verify the intermediate, combined result
- issues like overwriting data simply disappear when any file is only being written to once
This takes more lines of code, and I find it's easier to get correct: