When to run slower code

I would like to include some code that adds the most recent trial data to a file, to prevent data loss in case of the computer dying. I am aware that saving data to a file will be a little time consuming and I do not want critical timings to be affected by it.
My question is when should I execute this code? In builder view, can I add it to the ‘End Routine’ box of custom code without any problem, or should I be adding a ‘static screen period’ somewhere?

Yes, if your inter-trial-interval duration isn’t critical then doing this at End Routine is sensible. You could make a call to logging.flush() too so that the log file gets appended at the same time