You have to get the line number in some manner in order to ensure that you get the correct line, otherwise you'll end up deleting either the wrong line, or the last line.
If you're using $read in your script, then you can use $readn to return the line (storing it in a variable if you can't do the deletion immediately)