AFAIK the old file natives open a file, seek to the file you specified do the read/write and then close the file. Sequentially reading to find the line you want is a slow task..
Try using ftell and fseek to overwrite a line (I've never tried it but I think it might work), but I think i've read somewhere that the only way to do this is to create a backup file and sequentially copy lines from the file into the backup. When you reach the file you want to modify do the modification and copy that across. Once you reach the end of the file, delete it and rename the backup to the original name.