If you transfer a program to the flash using isp, then you no longer have a BOOTLOADER on the Atmega, which is deleted when flashing via isb. But it is important that you still burn the Bootlodar with ISP on the Atmega for one time, so that the fuses are set correctly, otherwise the Atmega cannot run with the external quartz and then neither the times of millis nor the baud rates of the serial are correct communication, as this depends on the clock. with a brand new Atmega328 the clock is set to internal I don't know exactly whether it is 1MHz or 8MHz, in any case it does not match the external 16MHz crystal. When burning the bootloader, the ARDUINO IDE also sets the FUSEs correctly at the same time, and these are then retained if the bootloader is deleted when the program is flashed via ISP.
So try it by first burning the bootloader for a UNO board (IDE -> Tools> Board: UNO) Then make sure that your ISP programmer is selected under PROGRAMMER. then choose IDE -> Tools -> Burn Bootloader. Then flash your program again, after that it should work.
Have you only tested your program in connection with the MEGA or have you also tried it once on a UNO to make sure that it also runs perfectly there?