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.