Don't change a file again if it's already been done.

When using `append_if_not_found=True` or `prepend_if_not_found=True`
the file will grow infinitely as replace() didn't check until now
whether the change has already been made.

This fixes this behavior (#18612).
Use a separate read-only 'fileinput' object for initial check.

Before any of the actual operations happen, 'replace()' will check
first, whether the change has already been done.
If the same 'fileinput' object is used for this initial check as for
the actual operation, the initial check will leave an empty file as it
doesn't return any modifications.

This can be prevented by doing the initial check on a read-only
'fileinput' object.
Remove dead code - 'search_only' is handled now earlier.
Merge pull request #18615 from eliasp/2014.7-modules.file.replace-issue-18612

Don't change a file again if it's already been done.