But it's mandatory that the destination file does not exists, otherwise the query will fail, this is done to avoid overwriting files with random content. The alternative, if you want to append results, for example, is to use mysqldump or something like this:
mysql -uVAR -pVAR -e "SELECT 'hello';" > /tmp/random.log
To execute, if using PHP, from exec().
But looking at previous answers, now I'm not sure is this you where searching for.
If you're in one of those predicaments where cls.__private attributes just aren't enough since they can easily be accessed through inst._cls__private, and you need something a little more secure, here's ...