output query to file