Script compiles but file does not create output

Hi, I’ve made a script to export a Bezier path to a text file for a 3D game I’m making.

import bpy
import pickle

def write(filename):
    obj = bpy.data.curves["Track"]
    splines = obj.splines
    with open('track.txt','w') as f:
        for spline in splines:
            bezier = spline.bezier_points
            for point in bezier:
                for r in point.handle_left:
                    f.write(str(r))
                for r in point.co:
                    f.write(str(r))
                for r in point.handle_right:
                    f.write(str(r))
                f.write(str(point.tilt))
                f.write(str(point.radius))

The script compiles and I’ve tried to print the values to the console and it works. The problem is that the function when called from the console doesn’t do an output file. Anyone have any idea for the fix? :confused: