Update: I still haven't figured out why it doesn't work but managed to find a workaround.
Workaround Solution
I created a shell script that does what I need: updates a property of the server.properties
file:
#!/bin/bashproperty=$1 # property to changenewVal=$2 # value to assign to the propertysed -i "s/^${property}=.*/${property}=${newVal}/" server.properties
which I call from the C# application, passing the values I need, as follows:
ExecCommand(serverName, $"/bin/bash update-server-property.sh gamemode {newValue}");
This way the file gets updated as it should :)