Dave asked if it was homework primarily because it was phrased much like a homework assignment. It's hardly an "insult", but it's useful to know because then answers can be catered to that. For homework, than the aim was to learn something. Being given a working solution won't help you if the same topic comes up later. Conversely, if the solution is needed for the task it performs, than it would simply be more important to have the "solution" - a working batch script- as learning is more "secondary" in that scenario.
As to the problem.
You can iterate through all the lines in a file using an appropriate "for /F" command.
setlocal enabledelayedexpansion
for /F "tokens=*" %%A in (fruit.txt) do (
echo %%A
)
You can use command prompt to replace text within an environment variable via set:
set line=%%A
set result=%line:APPLE=PEAR%
You can use >> and > to redirect echoed output to a file. With this problem I'd suggest a temporary output file, and after the for command finishes, erasing the original file and renaming the temporary file to the original name.
From what I can tell, the replacement feature of "set" doesn't seem to work if the find or replacement text has spaces- not an issue here since APPLE and PEAR would be hard-coded as per the description, but worth considering if this will be expanded in some way.