In addition to Lafada's answer:
If you don't want to pass any values to the function, then you can store all the necessary data in the module as well:
# mymodule.py
filename = 'c:\\temp\\fileout.txt'
data = """
This is the
multiline string\n
which you want to write to the file
"""
...
def write_data_to_file():
with open(filename, 'w') as fp:
fp.write(data)
Assuming you have saved the above to mymodule.py, you call the function like so:
import mymodule
...
mymodule.write_data_to_file()
or, if that's the only function in the module that you need, and you want to use it lots, to save on typing:
from mymodule import write_data_to_file
...
write_data_to_file()
Note that mymodule.py must either be in the working directory of main script you are running or somewhere that is included in your PYTHONPATH environment variable.
See the python docs for more on modules.