Learning to play with others is a skill that needs to be learned just like any other thing that you need to learn to be able to play.
"I’ve practised a piece all week and have it pretty close to perfect"
How do you know it was "close to perfect"? Are you recording or videoing yourself and then playing it back? What you think you hear when you are playing and what you are actually playing could be very different. Any inconsistency in tempo may not be noticeable by yourself but could be a train wreck when playing with others. The recording or video of you playing may show you some stuff you don't realize is an issue otherwise.
Do you practice with a metronome? This could be very helpful. I highly recommend using one.
Do you have access to the backing track at home? If so, play to it as this will help get you used to it. If not, youtube has lots of tracks. Ask your teacher for a copy or if they can provide you a link to a video that is in the correct key/tempo/style that you can practice to.
Is there someone you can play in front of at home? A friend or family member would work fine. Your problem could all just be nerves. Practice preforming in a safe place in front of people that will still love/like you if you aren't great will help ease the nerves and get you used to playing in front of people.
You are taking a class and the instructor knows your playing level and has probably heard this issue in class and is much more likely to be able to help you with it (more so than some random person on the internet who has never heard you play). Ask them for help.
Finally, if you have made friends with anyone in the class ask them to get together and play/practice. You will both improve by doing this. Either one of you might see something in the other player that you can learn from or teach each other. Part of being a musician is making music with others and no better way to do this than to make music with someone that is at the same or similar level as you.
This is a life long journey and the most important thing is stick with and work through issues as they come up. Try not to get discouraged. EVERYONE has problem periods when playing at all levels and the players that become great are the ones that work through them and keep going.
Good luck!!