i dont think its penile cancer as its a rare cancer, probably happened due to friction while masturbating or could be some kind of bacterial infection ,best way is to consult a doctor