There is no limit on how many times you can fail the written test and retake the exam. Every time you fail the exam, you have to re-register to take the exam. Thus you will pay 150 USD to FAA for the re-registration. Failing the exam multiple times is not an option. Study carefully and prepare well to pass your IFR written test on your first attempt. I want to tell you that prepare well enough before your second attempt for retaking. Regardless you will pay the registration fee of 150 USD. Passing the exam at once will benefit you during your check ride. Once the check pilot notices you failed your instrument written test multiple times, he might go the extra mile to test your flying skills and IFR knowledge.