Well you'll have to change it to not use append mode and rewrite the entire file.

Code:
fs.openAsync(fl, FileMode.WRITE);
xml += '<Photo imagem="NodeToBeAdded.jpg" legenda="Node to be added" />';
fs.writeUTFBytes(xml);
fs.close();
You might be able to make it more efficient by seeking to the position in the file where you want to write and writing, but I'm not 100% sure how that'd work.