in reply to file is replaced

Have a look at $i in sub xml_output.
It's always 0 when you create the file.
Try passing $i in from the main program and incrementing it there.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.