Glad I'm not the only one who had suspicions of him before that scene. Ever since his first appearance when he was taking those memories I was watching him throughout the whole movie waiting for the backstab. I felt so bad. Well played, Pixar.
they obviously did it intentionally. First encountered stealing memories, hinting that Riley has forgotten him, Joy or Sadness or whoever being suspicious of the shortcut. He's like the anti-Lotso