I thought this one was worth blogging. To save the output of an SQL query in a file simply do this:

SELECT *
FROM table
INTO OUTFILE "/tmp/filename.txt"

Produces a tab delimited file with the outputs of the query - pretty simple...

SELECT order_id,product_name,qty
    FROM orders
    INTO OUTFILE '/tmp/orders.csv'
        FIELDS TERMINATED BY ','
        ENCLOSED BY '"'
        LINES TERMINATED BY '\n'

Will enclose the fields in quotes separated with a comma.