Of course you're right. I didn't read your code very carefully and was under the impression that you use Folder::findOrMake($this->URLSegment) each time "onBeforeWrite" is being called. Sorry, maybe it's because of the lacking indentation ;)
Changed my code in the previous example to use 'Folder' instead of 'File'.
The onBeforeWrite function on the DataObject would simply ensure that the file is located in the designated folder (defined by it's "holder" Page).