in reply to Re^2: file is replaced
in thread file is replaced

This is because you redefine $i in your sub and start from 0 each time.
change;
sub xml_output { my ($output, $tag, $fh,$i) = @_;
to;
sub xml_output { my ($output, $tag, $fh) = @_;
This will give you 0.xml and 6.xml.
This is because you increment $i each time you write a tag.
Move the $i++ to just after your open statement to count correctly.