I had been hitting my head against the wall when I couldn't get an edited XML file to save due to file permissions, even though I knew that it was OK.
Eventually I realised that for some odd reason, when I went to save the XML file, it would try to write the file to the root directory.
As such, use realpath() to keep the complete system path to the XML file when you load it:
<?php
$myfile = 'myxml.xml';
$myfile = realpath($myfile);
$doc = new DOMDocument('1.0');
$doc->load($myfile);
$root = $doc->documentElement;
$title = $doc->createElement('title');
$title = $root->appendChild($title);
$text = $doc->createTextNode('This is a title');
$text = $title->appendChild($text);
$doc->save($myfile);
?>