First we have a system of primary elections, and in many jurisdictions your party registration status determines which primary you can vote in. You have to be registered Democrat to vote Democrat, registered Republican to vote Republican, etc. The local election board is the one who oversees to vote, so they need to know your party registration in order to make sure you get the right ballot and the right ballot information (which is sent by mail beforehand). In many jurisdictions you can also "decline to state" and then in a primary election you have to tell them each time which ballot you want.
Second, it's used in state redistricting. Having this information be public allows auditors to check if redistricting is resulting in gerrymandering.
In other countries parties run their own candidate selections as private business and the state can’t meddle in it, so the state doesn’t have to ask what what your affiliation is.
Disclaimer: I'm not complaining about how it is in Germany/other countries in Europe. The trust in government is quite high here, and for a good reason :)