There are multiple purposes for scanning the passport:
- They confirm the legitimacy of the document.
- It pulls up your record in their internal/system databases.
- It pulls up your immigration history.
- It pulls up your information from other related government organizations (for example, the State department - which issues the visas)
Keeping in mind that USCIS is a federal agency; it is reasonable to believe they have information on people that is available at the federal level - for example, a federal warrant.
As far as seeing things in other countries; to an extent they demand this information because all people traveling to the US are subject to delivery of their API (Advanced Passenger Information) which includes information about your itinerary, port of embark/disembark; travel documents; travel reservation information and possibly payment method(s). So already they have a large treasure of your information.
As far as sharing information - the most common source of shared information on non-citizens is Interpol (the International Police) which is what some governments (and private organizations) can use.
Interpol does issue arrest warrants which are (supposed) to be honored by all those states that are bound to the Interpol agreement. This is one source of shared information.
Of course beyond this, countries with close diplomatic relations or other intelligence agreements do share information. The US is party to such agreements such as the UKUSA Agreement (which covers the UK, Canada, New Zealand, Australia) and involves sharing of information and intelligence.
Such information is used (among other areas) for screening passengers to identify high-risk or otherwise flagged persons.
However, unless explicitly shared - this information is not visible beyond the normal purview of the agency that holds the information. For example, your speeding ticket in the US is not available to the border control in the UK (and vice versa).