Problem with printing JSON strings into text file using NodeJS

I am recieving textarea data from html page using xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); POST request from client. I am trying to print the same data into a text file on server by converting the object into JSON string. Some characters got modified in the resulting text file.

HTML:

function postProgram(req, ID) {
var xhr = new XMLHttpRequest();
xhr.open("POST", req, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send(document.getElementById(ID).value);
}

NodeJS:

app.post('/ExCode.f90', (req, res) => {
  console.log(req.body);
  var data = JSON.stringify(req.body);
  data = data.slice(2,-2);
  data = data.replace(/\n/g, 'n');
  fs.writeFileSync('./BasicDocument/ExCode/ExCode.f90', data);
});

Resulting Output File:

PROGRAM ExampleCode
!Example Code of addition of two numbers
IMPLICIT NONE

REAL :: a, b, c

!Numbers to be added
  a ":" 1;  b = 2

!Add Operation
  c = a   b

!Print Output
print*, "Third Number:", c

END PROGRAM ExampleCode

Expected Output File:

PROGRAM ExampleCode
!Example Code of addition of two numbers
IMPLICIT NONE

REAL :: a, b, c

!Numbers to be added
  a = 1;  b = 2

!Add Operation
  c = a + b

!Print Output
print*, "Third Number:", c

END PROGRAM ExampleCode