It seems that the flag `RecursiveIteratorIterator::SELF_FIRST` is messing up with the directory structure. After removing it, the `$phar->buildFromIterator` method works as expected.