It looks as if your function 'cutline()' gets called for every line you need cut. And by looking at the code for cutline(), your parsing the file into an array with file() and opening a pipe to the file for each line you need cut.
Why not try something more like:
1. open the file
2. start loop
3. do your searching/comparison algorithm
4. delete lines you want to delete.
5. end loop
6. write and close file handle
Your currently doing:
// first iteration
1. open the file parse into aray
2. open pipe to same file
3. do stuff to data
// second iteration
1. open the file parse into aray
2. open pipe to same file
3. do stuff to data
// third iteration
1. open the file parse into aray
2. open pipe to same file
3. do stuff to data
// fourth iteration
1. open the file parse into aray
2. open pipe to same file
3. do stuff to data
// fifth iteration
1. open the file parse into aray
2. open pipe to same file
3. do stuff to data
Sorry no input on the wierd character, I would fix this first, then tackle the character.