How do I write into a file (css)

What’s wrong with saving CSS to the database? That is the correct approach. And that way, you can simply output the options to a function, which can be enqueued properly, using wp_print_styles, and entirely avoid file operations/writing to .css files.