Ok, maybe I'm wrong, but I thought my first post was suggestions.... but, here ya go, I'll explain:
$lines is an array. This means, using the file() funciton, you've created an array with each element corresponding to a line in the file read via the file() function.
So, that means, if the names.txt file looked liked this:
Allen
Bob
Mary
your $lines array is this:
$lines[0] = Allen
$lines[1] = Bob
$lines[2] = Mary
What you want to do is loop through this array and compare each value to see if it matches the $name var passed to the script.
Last, and not least, assuming you put in the loop code (read up on list() and each() functions), you need to write the file() back to disk. As it stands now, you are reading the file in (actually reading it twice with file() and fopen()).
So, to summarize:
1. Read the file in (using the file() function.
2. Loop through this array. If the name is not equal to the current value in the loop, add the value to another var (call it $new_file).
3. when done, fwrite() $new_file to the $namefile var on disk.
Keep in mind, if you do this, if you have two poeple with the smae name, both will be removed.