did you know that apache (and of course php) runs as un unprivileged user??? (user "nobody", for example).
it doesn't matter what user you're login in as into the database (by the way, the backend runs as user mysql, or another unprivileged user).
why don't you try to save your files into a publicly writable directory???? something like:
$fp=fopen("/tmp/text1.txt", "wb");
you should not put files in your root directotory, it's a common practice to use small partitions for the /.
oh, another thing: the user that you're using to log in into the database, is an internal mysql user, it has nothing to do with the real root user.