I know that PHP can create a brand new text file but can a PHP function create an html or PHP file also with some code inside the files?
Yes it can but make sure your files have the proper permissions ie writable. If it doesn't then you will get a 500 Internal Service Error.
So... I can read an html or php file and copy it with some new code inserted inside it where I want to a new file with a new name?