Without knowing anything about the code you have developed so far, you may want to look into a Producer/ Consumer architecture as a way to use queues to effectively run multiple loops. Saving data to a file will involve some delay, so this is the sort of operation that should be decoupled from the sampling loop.
Again, without knowing anything about the hardware you are using, I wouldn't have thought a sampling frequency of 500Hz should be too difficult to achieve with the right architecture.