I think everyone has raised their arm to wave at someone they thought was a friend, and when they realized it wasn't they'd think it was too embarrassing to just raise the arm without doing anything with it, and therefore the scratching of the head/back/whatever.