ひまなときなにをしますか。(What do you do in your free time?)
A popular beginners’ textbook in Australia has this sentence in the chapter dealing with “hobbies,” so many HSC students know this sentence very well and recently one of my most studious Year 12 students wrote:
Nothing is grammatically wrong with this sentence but it does not reflect what she meant to say or what she has actually done.
ひまなとき is when you have nothing to do and you are (almost) bored. Students at school shouldn’t have ひまなとき as they are supposed to spend free study periods doing something productive. Those free study periods should be called 自習（じしゅう (self-study)）時間（じかん）, not ひまなとき.
So she should have written “今日、自習時間に 日本語の作文を書きました。” because she actually wrote a serious essay in Japanese during her study period.
The impression most Japanese native speakers will get when they see “今日ひまな時、日本語の作文を書きました。” is that she wrote a random, not very important essay in Japanese as she had nothing else to do.
By using the phrase ひまなとき, that gives the impression that whatever she did/was doing was neither urgent nor very important.
Nowadays, people don’t really have ひまなとき any more. A (bit of) spare time should be described as 空（あ）いた時間（じかん） or maybe a phrase, 時間（じかん）が空（あ）いたら (= when/if I have some spare time) should be used.