Selena Gomez' fiance helped write a Katy Perry hit that appeared on the biggest album of Perry's career so far.