Hello @Rebecca and welcome to the forum!
I think this is a nice quaint beginning piano piece! Regarding your questions about accidentals, usually F#'s and Bb's are in C major are first used as part of dominant 7th chords to make the listener expect the modulation to G major and F major, respectively. If you're modulating to G major, a D7 chord would be expected with an F# in the middle. If modulating to F major, a C7 chord would be expected with a Bb as its 7th. Then, once you've established the change in key, you stay in each respective key by continuing to use the F# or the Bb in the melodies and harmonies. If at some point you want to return to C major, then a G7 chord would be expected somewhere to bring you back. That is just a very basic harmonic expectation, and there's other ways to modulate to different keys (besides just using secondary dominants). And to give you credit, you do in fact use those chords at times to establish the key you're in such as in bar 14. There are also some harmonically weaker parts of your sonata, such as measure 11 where you have a cross-relation (the previous bar had F#'s in the melody and then you suddenly go straight into an F natural in a different voice which sounds a bit jarring). The sections with extended up and down scalar motion are also kind of weak. Not only because there's no accompaniment but because you seem to indiscriminately include different accidentals in the scales. I'll leave it at that for now. Overall though, this isn't bad, especially since you use some unusual harmonic progressions in the beginning. Thanks for sharing!