The user stories in Scrum are usually written by the product owner. The product owner has a deep understanding of the market and the users, which allows them to create user stories that are focused on delivering value. They collaborate with the team to prioritize and refine these stories throughout the Scrum process.
Pretty much anyone involved in the project can write a user story, like developers, product managers, or even end-users if they have a clear understanding of the requirements.
Often, it's the role of agile team members such as product managers or even developers who have a good understanding of user needs to write user stories. They focus on capturing the user's perspective and requirements.