Reform MP Lee Anderson has been told to apologise in the House of Commons for "swearing twice at a security officer after his pass did not work" as he tried to enter parliament.