Memory usage improvement

There is no need of storing $sql_file and $output in memory, this will only make this script unusable on large databases ("Fatal error: Allowed memory size of XXX bytes exhausted" bug). Should write stuff directly to file.