Getting signature error while installing a different version of the app

Recently I install a custom ROM named eelo It comes with pre-installed Telegram app. After much research I was able to uninstall if from the system with the command adb shell pm uninstall --user 0 org.telegram.messenger. But when I tried to install the new apk with adb install telegram.apk I got the following error

adb: failed to install telegram.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package org.telegram.messenger signatures do not match the previously installed version; ignoring!] 

I also tried uninstalling with this adb uninstall org.telegram.messenger but it gave out Failure [DELETE_FAILED_INTERNAL_ERROR]. With further research I found out that I can install the new .apk with different if I comment the section in /data/system/packages.xml referring to telegram. But after making the change when I reboot it get back to the unedited version.

Currently using Android Nougat 7.1.

Can anyone tell me the reason as to why this happens and how I can stop it from happening? And how would I be able to install a different version of the app?