Why does the Atmega328 USART get trapped in a loop?
You cannot have the same UART wired to both the PC via USB serial and also the mobile modem, without causing such mixups.
You need a second UART, either hardware or software as typical Arduino examples for your platform in this role use.
You also do not want to use delays in serial code.
Basically, start over from a working example and only attempt to reimplement by hand once you thoroughly understand that example.
Ideally you would also switch to a better processor with at least two hardware UARTs.  Likely few but the Arduino folks would try to force this one to do that job when there are better, cheaper choices for an application needing two UARTs.