How do I save data into a custom table on form submit?
As per the change record, drupal_write_record has been removed, with the new advice being:


  Developers should use \Drupal::database()-&gt;merge(), the Entity API or one of the provided services, like key value.


As you're using a custom table, you'll need the first method. An example from that change record:

\Drupal::database()-&gt;merge('example_deleted_entity_statistics')
  -&gt;key(array('type' =&gt; $type, 'id' =&gt; $id))
  -&gt;fields(array('count' =&gt; $count))
  -&gt;execute();


As always, inject the database service if possible, rather than requesting it from \Drupal.