For small files I see little need for with open(...) as f:. A Path object can read or write the whole thing in one call.
from pathlib import Path
cfg = Path("settings.ini")
text = cfg.read_text(encoding="utf-8")
cfg.write_text(text.replace("debug = true", "debug = false"), encoding="utf-8")
read_text opens the file, reads it all and closes it again. write_text does the same in the other direction and replaces whatever was in the file. There are read_bytes and write_bytes for images and other binary data.
I’d always pass encoding="utf-8". Without it Python uses the platform default, which is UTF-8 on Linux and macOS but has been something else on Windows, and that’s how a script breaks on the first accented character on someone else’s machine.
Two limits to keep in mind. The whole file goes into memory, so for a multi gigabyte log I’d still loop over lines with open(). And write_text isn’t atomic: if the script dies halfway, the file can be left half written. For an important config, write to a temporary file next to it first and then move it into place with Path.replace().
Further reading: pathlib Path.read_text, pathlib Path.write_text