Problem with Saving MQTT Payload Data to CSV or TXT File from Portenta X8

Hello everyone,

Following this tutorial (https://docs.arduino.cc/tutorials/portenta-x8/multi-protocol-gateway), I've encountered an issue with saving data from the Python code to a csv or even a txt file.
I'm using an ESP32, which sends the data to the Portenta X8 that's connected to the Max carrier. When I run the code, the data is received and printed, but it's not saved to the file. Could the problem be related to the Arduino and Linux layers?

Here's the data being successfully sent from the ESP32 to the Portenta X8:

Here is the modification I made to the part of the code:

I tried using f.write(str(float(decoded_mqtt_payload))) and f.write('hello'). However, both attempts did not work, and the resulting file is totally empty.

Thanks in advance.

The problem is solved. Thanks everyone.