If you can identify when you're at the split point (the point where the data to stay in file A ends, and the data to move in file B begins), and the data to move is "the rest of the file", the best approach is to truncate
file A after copying the excess data.
Pseudo-code for it would be:
moving = False
splitpoint = None
for line in infile: # infile must have been opened in r+ mode to allow modification
if moving:
outfile.write(line)
elif should_start_moving():
# Assumes you know you're at the split point when you have read line 3,
# before you see line 4
splitpoint = infile.tell() # Save off split point
moving = True
# If we ever reached the splitpoint, we want to truncate what we moved
if splitpoint is not None:
infile.seek(splitpoint) # Go back to where we saw the split point
infile.truncate() # Cut off the rest of the file