I don’t know why when I’m trying the same code to export a new dataset I’m getting the following error.
TypeError: ExportSegmentsClosedSurfaceRepresentationToFiles argument 2: method requires a vtkMRMLSegmentationNode, a vtkMRMLSegmentationStorageNode was provided.
It seems that this returns the wrong node (the segmentation storage node instead of the segmentation node itself). I suggest using a more robust way to get the node.
slicer.util.getNode('*Segment*') returns the first node in the scene that contains Segment in its name or ID (including all the hidden nodes). There can be many nodes like that in the scene: the segmentation node, the segmentation display node, and segmentation storage node. getNode helper function (especially when it is used with wildcards as input) is only recommended for quick testing and troubleshooting.
If you specify the kind of node you are looking for (vtkMRMLSegmentationNode) and you only have one node of that type in the scene then the result is always as you expect.