If I buy a put option (which would be an option to sell stocks as far as I understood), who will provide the stocks to sell if I decide to exercise it? Should I have/provide the stocks or is it the option writer who provides them? And at what price would they be provided?
A put gives the owner the right to sell the stock at the strike price. If you exercise your long put, you must deliver the shares if you own them. If you do not own them then if the shares are borrowable, your broker will borrow them from a 3rd party and give them to you for delivery. This is called shorting.
To short, you will need a margin account, approval for shorting and the necessary margin to support the position (not a good idea for anyone other than an experienced trader). In order to close the short position, you will have to buy the shares to return them to the lender.
If the shares are non borrowable, you'll have to buy the shares immediately in order to deliver them and fulfill your exercise. Note that it usually makes more sense to sell the put, unless you actually want to go short.
If I choose to sell back the option to the writer, which I understood is called a buy to close, is the writer obligated to buy it back? Or can they say no, in which case I would have to wait until expiry?
Selling your long put is called sell to close. Though possible, it would be highly unlikely that your counterparty would be the original writer.
Like stocks, options have market makers who are required to trade at their quoted prices. Traders can place orders at higher bids and lower asks, becoming the market. Either way, you will be able to close your position.
Some unsolicited advice? Read a few option books before you dive into option trading. You're likely to save yourself a lot of money if you do so.