Renames file-name references inside files in a directory
For each filename you want to replace in the content, you open each file, mutate the content and write it back. Meaning that if you want to modify 10 filenames, you open each file 10 times and write it back 10 times.

This is clearly inefficient, you should open each file once, perform the 10 modifications you need and then write it back.

You also recompute new_name for each file which is not necessary as you could store this information somehow.

Last but not least, you could define some function to organize the code and give meaning to your actions:

"""
Rename references to filenames inside content of files in a directory.

Rename file references containing `-` with `_`
"""

import os


def update_references(conversion_table, directory):
    for root, dirs, files in os.walk(directory):
        for filename in files:
            path = os.path.join(root, filename)

            # Read initial content from file
            with open(path) as f:
                content = f.read()

            # Update content with new references
            for old_name, new_name in conversion_table.items():
                content = content.replace(old_name, new_name)

            # Update file with new content
            with open(path, "w") as f:
                f.write(content)


if __name__ == '__main__':
    # A file containing filenames that you want to change.
    # Already generated
    with open("filenames.txt") as filenames_to_change:
        names = filenames_to_change.read().splitlines()

    renamed = {name: name.replace('-', '_') for name in names}
    update_references(renamed, './Test/')