I've long used this method to write files to the file system using SQL.
This method employs the SQL sp_OACreate and sp_OAMethod procs to do the writing. Now in SQL 2012 that method is not working for me. I switched to the XP_CommandShell method and that works fine.
So, here is the documentation of how to write a text file using XP_CommandShell