file is a shortcut function for fopen ... fread ... fclose, only for reading, in a comfortable one-step way.
you don't have to close a file "opened" with file(). it's already included in that function.
have a look at fopen, fread, fwrite, there are the examples how to do this technically.
in order to replace just one line, you'll have the whole file again, with the updated line in it.