Serial Port appends \r carriage return to each line and repeats boot log for each line

I'm using python programming to boot the board and run some tests and post results into txt document. By using read() log repeats for each character, after using readline(), booting log is repeating for every new line it receives.
Any suggestion to handle the carriage return overcome the issue will be helpful.

#!/usr/bin/python3
import serial
import time

def enter_factory_mode(panel_type,panel_uart_com):
    ser=serial.Serial(panel_uart_com,115200,timeout=0.5)
    if(ser is None):
        print("open serial failed")
        return False
    ser.write("\x03".encode())
    print("%s do test" %panel_type)
    set_mode_bit = False
    
    response = ''
    s_temp = ''
    timeout = time.time()+120
        
    while(True):
        s_temp = ser.readline().decode("utf-8", "ignore")    
        response += s_temp
        if timeout<time.time():
            ser.close()
            return False
        if(set_test_mode_bit is False):
                if(response.find("Reset cause: WDOG") != -1):
                    ser.write("\n".encode())
                    ser.write("setenv testmode 1\n".encode())
                    ser.write("boot\n".encode())
                    print("setenv factorymode 1")
                    print("boot")
                    set_test_mode_bit = True
                    response = ""
        else:
            print(response)
            if(response.find(login_string) != -1):
                ser.write("root\n".encode())
                time.sleep(1)
                ser.write("root\n".encode()) 
                print("user")
                print("password")
                time.sleep(1)
                print("go to testmode successful")
                set_testmode_bit = False
                ser.close()
                return True
                
    print("enter testmode failed")
    ser.close()
    return False
    
def write_command(ser,command):
    try:
        ser.write(command.encode())
        #time.sleep(1)
    except:
        print("error")    

def get_result(ser,time_delay): 
    response = ''
    s_temp = ''
    time_delay_temp = int(time_delay)
    if(time_delay_temp < 0.1):
        print("please input the right time delay")
    timeout = time.time()+time_delay_temp
    while(True):
        s_temp = ser.read().decode("utf-8", "ignore")
        response += s_temp
        if timeout<time.time():            
            break
    return response
    
def main():
    panel_type = ""
    panel_uart_com = "/dev/ttyUSB0"
    ret = enter_factory_mode(panel_type,panel_uart_com)
    if(ret is False):
        print('enter test mode failed')
        return False

    test(panel_type,panel_uart_com)
    
   
if __name__ == '__main__':
    main()

image of output:

When is response cleared?

@Rintin sorry, i didn't get you. can you rephrase the point.

You append stuff to response but where do you clear ( response = "" ) it in the while loop?

@Rintin printing response in else condition.
i'm making changes in the code as: s_temp = ser.read(1024).decode("utf-8", "ignore")
then observed there is difference in logs.


whenever it receives "\b\b\b 0 \r\r" it repeats the log.

You're chasing a symptom, not the cause. Its repeating because its REBOOTING! Figure out why it's rebooting and the "dupes" will go away,