I'm still not sure why it's happening in the first place, but I've added the solution to the Installation FAQ:
http://moodle.org/doc/?file=faq.html#fixdirroot
Installing and upgrading help
1.8.1 to 1.9 upgrade problem in config.php
This discussion has been locked so you can no longer reply to it.