404 error on dynamic stylesheet creation

The solution you’re using to get the stylesheets onto the page is a terrible method. WordPress provides the enqueue functions specifically to do what you’re trying to do. The codex page on wp_enqueue_style() explains exactly what you need to do. If you would like to add a dynamic version, there is a parameter for that.