I would guess there is an error somewhere in private key generation in your script... most likely because it doesn't include this patch from the botg.sh shell script:
0.0.3 -remake key if it's not exactly 64
I was already thinking that there probably was something off about the code used for generation. I still find it quite weird that they're invalid and valid at the same time though..

How exactly does KwFAa6AumokBD2dVqQLPou42jHiVsvThY1n25HJ8Ji8REf1wxAQb == KwFAa6AumokBD2dVqQLPou42jHiVsvThY1n25HJ8Ji8REGDgzcJ1 ? Does the checksum not matter with wif keys?
Or i guess they share the same private key, from which the adress is derived, and this WIF encoded from again, correct?