Follow these steps:
1) Make a stored procedure that creates a temporary table and inserts records into it.
2) Make a stored procedure that reads records from this temporary table and writes to a file. You can use this link: clickhere
3) Create an SQL job that sequentially performs steps 1 and 2.