how i can write a PHP file that overwrites .htaccess with the correct information
AFAIK this is not possible. Could your maybe share your "real" problem. You probably want to include some logic into .htaccess, right?
This is not possible, .htaceess is controls the permission from Apache, it is not possible to add some code in this file.
Short answer: Its not possible.
Long answer (that due to the lack of detail in the original question is still very short): What you are trying to do can (probably) be done in a much cleaner/better way. Elaborate your questions, state what you have tried and and what youre trying to achieve.
Rather than doing this, you could write a PHP file that overwrites .htaccess with the correct information.
What correct information? If you're using php to write css, and .htaccess is applying the HTML content type, add this line to your php: header('Content-Type: text/css');
. If you're doing something else, do something else.