Serial Monitor repeats println

the code is intended to obtain user input through the Serial Monitor.
the msg prints twice when code is run , there are no error messages, User input is accepted.

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(msg);
  while  (Serial.available() == 0 ){
  
 }
}

you just don't do anything if there is no user input and then the loop, loops... so the Serial.println(msg); is done again and again

I would suggest to study Serial Input Basics

Your sketch is incomplete.

I suspect you aren't handling line ending characters correctly.

Take a look at the examples in
Arduino Serial – Reading/Parsing
for how to read from Serial, and trim() off and line endings.